using System;
using System.Collections.Generic;
using DMS.BEs;
using DMS.BEs.Gifts;
using DMS.DAOs;
using DMS.Filters;

namespace DMS.Models.Impl
{
	public class MarketingModel : IMarketingModel
	{
		private readonly IInvoiceDAO invoiceDAO;
		private readonly IGiftStrategy giftStrategy;

		public MarketingModel(IInvoiceDAO invoiceDAO, IGiftStrategy giftStrategy)
		{
			this.invoiceDAO = invoiceDAO;
			this.giftStrategy = giftStrategy;
		}

		public Invoice GetWinner(int year, int month)
		{
			DateTime from = new DateTime(year, month, 1);
			DateTime to = from.AddMonths(1).AddSeconds(-1);

			IList<Invoice> invoices = invoiceDAO.GetByFilter(new InvoiceFilter { From = from, To = to });

			return giftStrategy.GetWinner(invoices);
		}
	}
}